package com.demo.sender.notice;

import com.demo.common.ResultData;
import com.demo.enums.NoticeTypeEnum;
import com.demo.request.NoticeReq;
import com.demo.sender.notice.dingtalk.DingTalkSender;
import com.demo.sender.notice.lark.LarkSender;
import com.demo.sender.notice.slack.SlackSender;
import com.demo.sender.notice.telegram.TelegramSender;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author wangfengchen
 */
@Component
public class NoticeSender {

  @Autowired
  private LarkSender larkSender;
  @Autowired
  private DingTalkSender dingTalkSender;
  @Autowired
  private TelegramSender telegramSender;
  @Autowired
  private SlackSender slackSender;


  public ResultData<Object> send(NoticeReq req) {
    NoticeTypeEnum typeEnum = NoticeTypeEnum.match(req.getChannel());
    if (ObjectUtils.isEmpty(typeEnum)) {
      return ResultData.fail("渠道类型错误");
    }
    // 判断发送消息类型
    switch (typeEnum) {
      case LARK:
        return larkSender.send(req);
      case DINGTALK:
        return dingTalkSender.send(req);
      case TELEGRAM:
        return telegramSender.send(req);
      case SLACK:
        return slackSender.send(req);
      default:
        break;
    }
    return ResultData.success();
  }


}
